/*
 * $Id$
 *
 * Copyright (c) 1998-2008 John Morrison.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */


/*
 * PasswordDialog.java
 *
 * Created on 15 June 2004, 17:45
 */

package com.jbolo.gui.dialog;

/**
 *
 * @author  John Morrison
 */
public class PasswordDialog extends java.awt.Dialog {
    
    private String password;
    
    /** Creates new form PasswordDialog */
    public PasswordDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        password = null;
        initComponents();
        setVisible(true);
    }
    
    public String getPassword() {
        return password;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        button1 = new java.awt.Button();
        textField1 = new java.awt.TextField();
        label1 = new java.awt.Label();

        setLayout(null);

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        button1.setLabel("OK");
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
            }
        });

        add(button1);
        button1.setBounds(270, 130, 33, 24);

        textField1.setText("txtPassword");
        textField1.setEchoChar('*');
        add(textField1);
        textField1.setBounds(60, 130, 170, 20);

        label1.setText("The game you are trying to join is password protected. Please enter the correct password to join");
        add(label1);
        label1.setBounds(0, 10, 350, 100);

        pack();
    }//GEN-END:initComponents

    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed
        // TODO add your handling code here:
        if (textField1.getText().length() == 0) {
            password = null;
        } else {
            password = textField1.getText();
        }
        setVisible(false);
        dispose();
    }//GEN-LAST:event_button1ActionPerformed
    
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new PasswordDialog(new java.awt.Frame(), true).show();
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Button button1;
    private java.awt.Label label1;
    private java.awt.TextField textField1;
    // End of variables declaration//GEN-END:variables
    
}
